import 'package:my_flutter_demo/exports.dart';

class CheckboxDemoPage extends StatefulWidget {
  const CheckboxDemoPage({super.key});

  @override
  State<StatefulWidget> createState() => CheckboxDemoPageState();
}

class CheckboxDemoPageState extends State<CheckboxDemoPage>{

  bool _isChecked = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Checkbox'),
      ),
      body: Center(
        child: Column(
          children: [
            Row(
              children: [
                Checkbox(
                  value: _isChecked,
                  onChanged: (bool? value){
                    setState(() {
                      _isChecked = value!;
                    }
                    );
                  },
                  activeColor: Colors.orange,// 选中颜色
                  checkColor: Colors.white,// 选择图标颜色
                  side: BorderSide(
                      color: Colors.orange,// 未选择边框颜色
                      width: 2.0
                  ),
                  shape: CircleBorder(),// 形状
                ),
                Text('用户协议')
              ],
            ),
            Container(

            ),
            InkWell(
              onTap: (){
                setState(() {
                  _isChecked = !_isChecked;
                });
              },
              child: Row(
                children: [
                  Checkbox(
                      value: _isChecked,
                      onChanged: (bool? value){
                        setState(() {
                          _isChecked = value!;
                        }
                        );
                      },
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5.0)
                      )
                  ),
                  Text('隐私协议')
                ],
              ),
            ),
            CheckboxListTile(
              title: Text('接受条款'),
              subtitle: Text('请仔细阅读用户协议'),
              secondary: Icon(Icons.article),
              value: _isChecked,
              onChanged: (bool? value) {
                setState(() {
                  _isChecked = value!;
                });
              },
              activeColor: Colors.orange,// 选中颜色
              checkColor: Colors.white,// 选择图标颜色
              side: BorderSide(
                  color: Colors.orange,// 未选择边框颜色
                  width: 2.0
              ),
              shape: CircleBorder(),// 形状
            ),
            CheckboxListTile(
              title: Text('请仔细阅读用户协议并接受条款'),
              controlAffinity: ListTileControlAffinity.leading,
              value: _isChecked,
              onChanged: (bool? value) {
                setState(() {
                  _isChecked = value!;
                });
              },
              activeColor: Colors.orange,// 选中颜色
              checkColor: Colors.white,// 选择图标颜色
              side: BorderSide(
                  color: Colors.orange,// 未选择边框颜色
                  width: 2.0
              ),
              shape: CircleBorder(),// 形状
              splashRadius: 1,
            )
          ],
        ),
      ),
    );
  }

}